<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="format-detection" content="telephone=no, email=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #div1>button,#div2>button{
            width: 80px;
            height: 30px;
        }
        #div1>div,#div2>div{
            width: 300px;
            height: 200px;
            border: 1px solid #000;
            display: none;
        }
        #div1>button.active,#div2>button.active{
            background-color: #e6578a;
        }
        #div1>div.active, #div2>div.active{
            display: block;
        }
    </style>
    <script>
        window.onload = function () {

            var tit = new Tab("#div1") //创建
            tit.on()  //初始化

        }  
        
        function Tab(id) {
            this.oD = document.querySelector(id)  //传参 大div
            this.aB = this.oD.querySelectorAll("button")  //获取button按钮
            this.aD = this.oD.querySelectorAll("div");     //获取div
        }
        
//      原型对象
        Tab.prototype.on = function () {
            for(var i=0;i<this.aB.length;i++){
                this.aB[i].index = i;
                var This = this;
                this.aB[i].onclick = function () {
                    This.change(this)
                }
            }
        }
        
//      原型对象改变的时候执行的
        Tab.prototype.change = function (oB){
            for(var i=0;i<this.aB.length;i++){
                this.aB[i].className = ""
                this.aD[i].style.display = "none"
            }
            oB.className = "active";
            this.aD[oB.index].style.display = "block"
        }
        
        
        
        
//      构造函数
        
        function Ha(Name,Sex,Age,Fine){
			this.name=Name,
			this.sex=Sex,
			this.age=Age,
			this.fine=Fine,
			this.say=function(){
				document.write(this.name+",性别："+this.sex+",今年"+this.age+"岁，"+"有"+this.fine);
			}
		}
		var ha=new Ha("小明","男","18","女朋友")
		ha.say();
		
		
		
		
//		工厂模式

     function creat(a,b,c,d,e){
			var Person=new Object();
			Person.na=a;
			Person.chu=b;
			Person.hg=c;
			Person.price=d;
			Person.sm=e;
			
			
			Person.say1=sayH;
			
			return Person;
		}
		function sayH(){
			document.write("名称："+this.na+"<br/>"+"出场地："+this.chu+"<br/>"+"合格证："+this.hg+"<br/>"+"价钱："+this.price+"<br/>"+"说明书："+this.sm)
		}
		var Person1=creat("北京现代","北京","2017","14万","本产品已合格")
		Person1.say1();
    </script>
</head>
<body>

<div id="div1">
    <button class="active">按钮1</button>
    <button>按钮2</button>
    <button>按钮3</button>
    <div class="active">内容1</div>
    <div>内容2</div>
    <div>内容3</div>
</div>

</body>
</html>